/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint.user_interface.tools;

import embeddedpaint.model.feature.AImageTool;
import embeddedpaint.model.layers.LayerManager;
import embeddedpaint.model.layers.LayerText;
import embeddedpaint.user_interface.tools.dialog.chooser.JFontChooser;
import java.awt.Container;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;

public class ToolsCreateTextLayer extends AImageTool
{
    private static final String M_LABEL_TEXT = "Create Text";
    private static final String M_ICON_PATH  = "images/text.png";

    public ToolsCreateTextLayer (LayerManager imageManager, JFrame application)
    {
        super(imageManager, application);
    }

    @Override
    public void actionPerformed (ActionEvent e)
    {
        ToolsCreateTextLayer.editTextLayer(m_application, m_imageManager, null);
    }

    public static void editTextLayer (Container application, LayerManager layerManager, LayerText layer)
    {
        JFontChooser jf           = new JFontChooser();
        boolean      alreadyExist = true;

        if (layer == null)
        {
            layer        = new LayerText();
            alreadyExist = false;
        }
        else
        {
            jf.setSelectdeColor(layer.getM_color());
            jf.setSelectedFont (layer.getM_font());
            jf.setSampleText   (layer.getM_name());
        }

        if (jf.showDialog(application) == JFontChooser.OK_OPTION)
        {
            layer.setM_name (jf.getSampleText());
            layer.setM_color(jf.getSelectdeColor());
            layer.setM_font (jf.getSelectedFont());
            layer.setM_text (jf.getSampleText());

            if (!alreadyExist)
            {
                layerManager.add(layer);
            }
        }
    }

    @Override
    public String getLabel ()
    {
        return M_LABEL_TEXT;
    }

    @Override
    protected String getIconName ()
    {
        return M_ICON_PATH;
    }
}
